<script>
  var searchInsert = function(nums, target) {
    if (nums.findIndex(item => item === target) !== -1) {
      return nums.findIndex(item => item === target)
    } 
    if (nums[0] > target) {
      return 0;
    }
    if (nums[nums.length - 1] < target) {
      return nums.length
    }
    for(let i = 0; i < nums.length; i++) {
      if(nums[i] <= target && nums[i + 1] >= target) {
        return i + 1;
      }
    }
  };
</script>